#!/usr/bin/python
# GM_apparent.py
'''Calculate distribution of apparent magnitudes.'''

import numpy

def apparent(simpars, phypars, DistMod, ExtMod, distriblist):
    for i in simpars:
        cmd = "%s = simpars['%s']" % (i,i)
        exec cmd
    for i in phypars:
        cmd = "%s = phypars['%s']" % (i,i)
        exec cmd
    # Create a blank 3d array for each subset of apparent magnitudes you are interested in
    appearance = []
    for i in range(0, len(limitset)):
        appearance.append(numpy.zeros((1,1,1), dtype=float))
    for i in range(0, len(MvList)):
        appmag = MvList[i] + numpy.add( DistMod[:,numpy.newaxis], c0*ExtMod )
        rho = rho0*distriblist[i]
        for j in range(0, len(limitset)):
            lolim = limitset[j,0]
            hilim = limitset[j,1]
            mask1 = numpy.greater(appmag, lolim)
            mask2 = numpy.less(appmag, hilim)
            mask = numpy.logical_and(mask1, mask2)
            maskeddistrib = numpy.multiply(rho, mask[:,numpy.newaxis,:] )
            appearance[j] = appearance[j] + maskeddistrib
    return appearance
